import { StorageService } from './../../../providers/StorageService';
import { UserService } from './../../../providers/UserService';
import { BasePage } from './../../basePage';
import { Component, Injector, ViewChild } from '@angular/core';
import { IonicPage, Slides } from 'ionic-angular';
import { Events } from 'ionic-angular';
import { PIC_URL } from "../../../providers/Config";
declare var Swiper;
/**
 * Generated class for the ShopPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-shop',
  templateUrl: 'shop.html',
})
export class ShopPage extends BasePage {
  index: any;

  
  shopOrderData=[]  //全部订单数据
  picrooturl = "";//图片服务地址
  userinfo = {}//获取内存中的数据
  
  @ViewChild('contentSlides') contentSlides: Slides;
  swiper: any;
  items: Array<any> = [0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 8];
  menus: Array<string> = ["全部", "待服务", "已服务", "查看评价"]
  constructor(injector: Injector, 
    public userService: UserService,
    public stc:StorageService, 
    public events: Events) {
    super(injector);
    this.picrooturl = PIC_URL;
    this.userinfo = this.stc.read('userinfo');
  }

  ionViewDidLoad() {
    console.log('我已经执行');
    this.initSwiper();
    // this.shopOrderAPI(0)
    console.log(this.stc.read("userinfo"));
    // this.shopOrderAPI();
    //this.data1.shop_id =this.userinfo['shop_id'];
  }
  ionViewWillEnter(){
    let index;
    index = this.navParams.data.stu;
    console.log(this.stc.read("back2"))
    if(this.stc.read("back2") !=null){
      index =this.stc.read("back2");
    }
    this.setStyle(index);
    this.contentSlides.slideTo(index,0);
    this.stc.removeItem("back2");
  }

  initSwiper() {
    this.swiper = new Swiper('.pageMenuSlides .swiper-container', {
      slidesPerView:4,
      spaceBetween: 0,
      breakpoints: {
        1024: {
          slidesPerView: 4,
          spaceBetween: 0
        },
        768: {
          slidesPerView: 4,
          spaceBetween: 0
        },
        640: {
          slidesPerView: 4,
          spaceBetween: 0
        },
        320: {
          slidesPerView: 4,
          spaceBetween: 0
        }
      }
    });
  }


  /**点击选择 */
  selectPageMenu(index) {
    console.log(index);
    this.setStyle(index);
    this.contentSlides.slideTo(index);
    // if (index == 4) {
    //   this.checkShopCommentsAPI();
    // } else {
    //   this.shopOrderAPI(index);
    // }
  }

  /**滑动选择 */
  slideChanged() {
    let index = this.contentSlides.getActiveIndex();
    this.setStyle(index);
    this.swiper.slideTo(index, 300);
    console.log(index)
    // if (index == 4) {
    //   this.checkShopCommentsAPI();
    // } else {
    //   this.shopOrderAPI(index);
    // }

  }

  /**样式切换选中 */
  setStyle(index) {
    var slides = document.getElementsByClassName('pageMenuSlides')[0].getElementsByClassName('swiper-slide');
    if (index < slides.length) {
      for (var i = 0; i < slides.length; i++) {
        var s = slides[i];
        s.className = "swiper-slide";
      }
      slides[index].className = "swiper-slide bottomLine";
    }
  }
  /**上一个页面 */
  dismissCLI() {
    this.navCtrl.pop()
  }
  // /** 获取店铺订单 */
  // async shopOrderAPI() {
  //   let data={shop_id:this.userinfo['shop_id']}
  //   let res = await this.userService.shopOrderAPI(data);
  //   console.log(res)
  //   if (res.code == 1) {
  //     //this.shopOrderData = res.data;
  //     res.data.forEach((e) => {
  //       if(e.id!=101){
  //         this.shopOrderData.push(e);
  //       }
  //     });
  //     console.log(this.shopOrderData)
  //     //this.events.publish('shop:created', this.shopOrderData, id);
  //   } else {
  //     console.log(res.msg)
  //   }

  // }
  
}